#include <iostream>
#include <vector>
#include <string>
#include <cstring>    // aggiunto per Qt 4.7

using namespace std;

#include "ppc_impl.h" // aggiunto per Qt 4.7
#include "VecUtility.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

VecUtility::VecUtility()
{

}

VecUtility::~VecUtility()
{

}

void VecUtility::Print(v_string& vec,ostream& os, const string& sx,  const string& dx)
{
	vector <string>::iterator it;
	for (it=vec.begin(); it!=vec.end(); it++)
	{
		os<<sx;
		os<<*it;
		os<<dx;
		if (it!=vec.end()-1)
			os<<' ';
		else
			os<<'\n';
	}
}

void VecUtility::Print(v_double& vec,ostream& os)
{
	vector <double>::iterator it;
	for (it=vec.begin(); it!=vec.end(); it++)
	{
		cout<<*it;
		if (it!=vec.end()-1)
			os<<' ';
		else
			os<<'\n';
	}
}


void VecUtility::Print(v_long& vec,ostream& os)
{
	vector <long>::iterator it;
	for (it=vec.begin(); it!=vec.end(); it++)
	{
		os<<*it;
		if (it!=vec.end()-1)
			os<<' ';
		else
			os<<'\n';
	}
}

void VecUtility::Print(v_ulong& vec,ostream& os)
{
	vector <unsigned long>::iterator it;
	for (it=vec.begin(); it!=vec.end(); it++)
	{
		os<<*it;
		if (it!=vec.end()-1)
			os<<' ';
		else
			os<<'\n';
	}
}

void VecUtility::Print(m_string& vec,ostream& os, const string& sx,  const string& dx)
{
	vector < vector<string> >::iterator it;
	for (it=vec.begin(); it!=vec.end(); it++)
	{
		Print(*it,os,sx,dx);
	}
}

void VecUtility::Print(m_double& vec,ostream& os)
{
	vector < vector<double> >::iterator it;
	for (it=vec.begin(); it!=vec.end(); it++)
	{
		Print(*it,os);
	}
}

void VecUtility::Print(m_long& vec,ostream& os)
{
	vector < vector<long> >::iterator it;
	for (it=vec.begin(); it!=vec.end(); it++)
	{
		Print(*it,os);
	}
}

void VecUtility::Print(m_ulong& vec,ostream& os)
{
	vector < vector<unsigned long> >::iterator it;
	for (it=vec.begin(); it!=vec.end(); it++)
	{
		Print(*it,os);
	}
}

int VecUtility::Find(v_string& vec, const string& str, v_ulong& pos)
{
	int tot=0;
	v_string::iterator r;
	ulong _pos=0;
	for (r=vec.begin(); r!=vec.end(); r++)
	{
		if (strcmp((*r).c_str(),str.c_str()) == 0)
		{
			tot++;
			pos.push_back(_pos);
		}
		_pos++;
	}
	return(tot);
}

int VecUtility::FindKey(v_string& vec, const string& str)
{
	v_string::iterator r;
	ulong _pos=0;
	for (r=vec.begin(); r!=vec.end(); r++)
	{
		if (strcmp((*r).c_str(),str.c_str()) == 0)
		{
			return(_pos++);
		}
		_pos++;
	}
	return(-1);
}

bool VecUtility::IsKey(v_string& vec)
{
	v_string::iterator r;
	v_ulong vu;
	for (r=vec.begin(); r!=vec.end(); r++)
	{
		if(Find(vec,(*r),vu) > 1) return (false);
	}
	return(true);
}

bool VecUtility::IsKeyInVec(v_string& vec_key, v_string& vec)
{
    v_string::iterator r;
    VecUtility vu;
    int i=0;
    for (r=vec.begin(); r!=vec.end(); r++)
    {
        if (vu.FindKey(vec_key,vec[i]) == -1)
        {
            return(false);
        }
        i++;
    }
    return(true);
}
